<template>
	<view class="myNeeds">
		<scroll-view @refresherrefresh="refresherrefresh" @scrolltolower="scrolltolower"
			:refresher-triggered="data.refresherBool" :refresher-enabled="true" scroll-y="true">
			<view class="list">
				<view class="listItem" v-for="(item,index) in data.result.list" :key="index">
					<view class="top">
						接单时间:{{item.startTime}}
						<text></text>
					</view>
					<view class="goods">
						<view class="left">
							<text>{{item.sellType == 'OFFLINE'?'线下':'线上'}}</text>
							<image :src="data.httpUrl+'/app/file/viewFile?fileId='+item.attachmentIds[0]"
								mode="aspectFill"></image>
						</view>
						<view class="right">
							{{item.title}}
							<text>{{item.content}}</text>
							<view class="priceText">
								<text>{{item.price.split('.')[0]}}</text>
								<text>.{{item.price.split('.')[1]}}</text>
							</view>
						</view>
					</view>
					<view class="info" v-if="item.appOrderSecure">
						<view class="">
							联系人：{{item.appOrderSecure.name}}
						</view>
						<view class="">
							联系时间：{{item.appOrderSecure.sendingTime}}
						</view>
					</view>

					<view class="bot">
						<text v-if="item.appOrderSecure && item.appOrderSecure.state != 'BEEN_SENT'" @tap="handeDelete(0,item)" class="cancel">{{item.appOrderSecure.state == 'NOT_SENT'?'取消':'开启'}}</text>
						<text  v-if="item.appOrderSecure" @tap="handeDelete(1,item)" class="cancel">删除</text>
						<text @tap="navTo('/pages/safeModeAdd/index?orderNo='+item.orderNo)" class="other">设置</text>
					</view>
				</view>
			</view>
		</scroll-view>

	</view>
</template>

<script setup lang="ts">
	import { reactive } from 'vue';
	import { queryOfflineOrderList } from '@/utils/api/map'
	import { cancelSecureMsg, dleSecureMsg } from '@/utils/api/index'
	const data = reactive<any>({
		httpUrl: getApp().globalData.baseUrl,
		result: {},
		obj: { pageNo: 1, pageSize: 10 },
	})


	uni.$off('safeMode');
	uni.$on('safeMode', () => {
		data.obj.pageNo = 1;
		requstList()
	})
	const refresherrefresh = () => {
		data.refresherBool = true;
		data.obj.pageNo = 1;
		requstList()
	}
	const handeDelete = (i, item) => {
		const b = i == 0 ? cancelSecureMsg : dleSecureMsg;
		uni.showModal({
			title: '提示',
			content: '是否执行操作？',
			success: (e) => {
				if (e.confirm) {
					b({ data: { orderNo: item.orderNo } }).then((res) => {
						if (res.code == 200) {
							if (i) {
								item.appOrderSecure = null
							}else{
								item.appOrderSecure.state = item.appOrderSecure.state == 'NOT_SENT'?'CANCEL_SENT':'NOT_SENT'
							}
							uni.showToast({
								title: '操作成功!',
								icon: 'none'
							})
						}
					})
				}

			}
		})

	}
	const requstList = () => {
		uni.showLoading({
			title: '加载中...',
			mask: true
		})
		if (data.obj.pageNo == 1) {
			data.result.list = [];
		}
		console.log(data.obj)
		queryOfflineOrderList({ data: data.obj }).then((res) => {
			res.data.list.map((item) => {
				item.price = item.price + ''
				if (item.price.indexOf('.') == -1) {
					item.price = item.price + '.00'
				}
				if (item.attachmentIds) {
					item.attachmentIds = item.attachmentIds.split(',')
				}
			})
			data.refresherBool = false;
			res.data.list = [...data.result.list, ...res.data.list];
			data.result = res.data;
			uni.hideLoading()
		})
	}

	const scrolltolower = () => {
		if (data.result.total != data.result.list.length) {
			data.obj.pageNo += 1;
			requstList()
		}
	}
	const navTo = (url) => {
		uni.navigateTo({
			url
		})
	}
	requstList()
</script>

<style lang="scss">
	.info {

		view {
			font-size: 28rpx;
			color: #938d8d;
			margin-top: 20rpx;
		}
	}

	.list1 {
		display: flex;
		margin-top: 30rpx;
		flex-wrap: wrap;

		.listItemImg {
			width: 128rpx;
			height: 128rpx;
			border-radius: 16rpx;
			margin-right: 16rpx;
			position: relative;

			>image:nth-of-type(1) {
				width: 128rpx;
				height: 128rpx;
				border-radius: 16rpx;
			}

			>image:nth-of-type(2) {
				width: 40rpx;
				position: absolute;
				right: -10rpx;
				top: -10rpx;
				z-index: 9;
			}
		}


		.zanwu {
			margin-right: 16rpx;
			width: 128rpx;
			height: 128rpx;
			border-radius: 16rpx;
			background: #F4F6FA;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			color: #C4C4C4;
			font-size: 15rpx;

			image {
				width: 46rpx;
				margin-bottom: 5rpx;
			}
		}
	}

	.confirmOrderBottom {
		padding: 24rpx 43rpx;

		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;

			image {
				width: 30rpx;
			}

			text {
				width: 30rpx;
			}

			font-size: 32rpx;
		}

		.bot {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 30rpx;

			.left {
				display: flex;
				flex-direction: column;
				font-size: 24rpx;

				text {
					margin-top: 10rpx;
					color: #FF263F;
				}
			}

			.right {
				width: 190rpx;
				line-height: 80rpx;
				background: #FF263F;
				text-align: center;
				border-radius: 80rpx;
				color: #fff;

			}
		}
	}

	.confirmOrderBottom_1 {
		>view {
			justify-content: space-between;
			// padding: 37rpx 35rpx;
			background: #fff;
			display: flex;
			align-items: center;
			margin-top: 32rpx;

			.left {
				display: flex;
				align-items: center;

				image {
					width: 48rpx;
					margin-right: 25rpx;
				}

				font-size: 24rpx;
			}

			>image {
				width: 36rpx;
			}
		}
	}

	.myNeeds {
		height: 100vh;
		background: #F4F6FA;
		display: flex;
		flex-direction: column;

		scroll-view {
			padding: 24rpx;
			flex: 1;
			overflow: auto;
		}

		.list {
			>view:nth-of-type(1) {
				margin-top: 0;
			}
		}

		.listItem {
			padding: 0 20rpx;
			margin-top: 24rpx;
			background: #fff;
			border-radius: 16rpx;

			>.top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #595959;

				text {
					color: #FF8C00;
				}

				padding: 20rpx 0;
			}

			>.goods {
				display: flex;
				align-items: center;

				.left {
					position: relative;
					width: 140rpx;
					height: 140rpx;
					border-radius: 24rpx;
					background: #ccc;
					margin-right: 16rpx;

					image {
						border-radius: 24rpx;
						width: 100%;
						height: 100%;
					}

					text {
						width: 72rpx;
						line-height: 40rpx;
						text-align: center;
						font-size: 20rpx;
						color: #FFF5E2;
						display: inline-block;
						position: absolute;
						left: 0;
						top: 0;
						box-shadow: inset -1rpx -1rpx 4rpx 0rpx rgba(255, 234, 160, 0.3);
						border-radius: 24rpx 0 24rpx 0;
						background: linear-gradient(223deg, #CD9A67 0%, #C69769 100%);
					}
				}

				.right {
					flex: 1;
					width: 0;
					font-size: 32rpx;
					display: flex;
					flex-direction: column;

					>text {
						color: #595959;
						font-size: 24rpx;
						margin-top: 8rpx;
					}
				}
			}

			>.bot {

				display: flex;
				justify-content: flex-end;
				padding: 24rpx 0;

				.cancel {
					width: 140rpx;
					line-height: 64rpx;
					text-align: center;
					border-radius: 32rpx;
					margin-left: 16rpx;
					color: #1313168c;
					border: 2rpx solid #1313168c;
				}

				.other {
					width: 140rpx;
					line-height: 64rpx;
					text-align: center;
					border-radius: 32rpx;
					margin-left: 16rpx;
					color: #6B64D3;
					border: 2rpx solid #6B64D3;
				}
			}
		}

		.score {
			margin-top: 24rpx;
			border-top: 2rpx solid #F4F6FA;

			view {
				display: flex;
				align-items: center;
				margin-top: 16rpx;

				text {
					// width: 0rpx;
				}

				image {
					margin-left: 12rpx;
					width: 36rpx;

				}
			}
		}

		>.top {
			background: #fff;
			display: flex;
			justify-content: space-between;
			padding: 38rpx 180rpx 0 180rpx;

			view {
				color: #595959;
				display: flex;
				flex-direction: column;
				align-items: center;

				&::after {
					margin-top: 20rpx;
					height: 4rpx;
					border-radius: 4rpx;

					width: 40rpx;
					content: '';
					display: inline-block;
				}
			}

			.active {
				color: #6B64D3;

				&:after {
					background: #6B64D3;
				}
			}
		}

		>.bot {
			padding: 8rpx 32rpx 20rpx 32rpx;
			background: #fff;

			text {
				display: inline-block;
				width: 100%;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				color: #fff;
				border-radius: 80rpx;
				background: #6B64D3;
			}
		}
	}

	.topRight {
		width: 48rpx;
	}

	.EVALUATED {
		display: flex;
		align-items: center;
		margin-top: 20rpx;

		image {
			width: 50rpx;
		}
	}

	.EVALUATEDbot {
		background: #6B64D3;
		width: 100%;
		margin: 0 auto;
		line-height: 88rpx;
		border-radius: 88rpx;
		text-align: center;
		color: #fff;
		margin-top: 50rpx;
	}
</style>